/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.vacoor.nothing.web.Nls;
import org.vacoor.nothing.web.entity.UuidEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

/**
 * @author vacoor
 * @Table T_USER
 */
@Entity
@Table(name = "T_USER")
@JsonIgnoreProperties({"hibernateLazyInitializer"})
@JsonPropertyOrder({
        "",""
})
public class User extends UuidEntity {
    /**
     * @Column required=true min=123 max=456 minLength=123 maxLength=124 pattern=
     * @Nls code="123"
     * @View mode=cru comp=input format=""
     */
    @NotNull
    @Size(min = 1)
    @Nls("1001")
    private String username;
    /**
     * @Column
     */
    @NotNull
    @Nls("1002")
    private String password;
    /**
     * @Column
     * @Nls code="8830"
     */
    @NotNull
    @Nls("1003")
    private String realname;
    /**
     * @Column
     */
    private String phone;
    /**
     * @Column
     */
    private String email;
    /**
     * @Column
     */
    private Boolean enabled;
    /**
     * @Column
     */
    private Boolean locked;
    /**
     * @Column
     * @View ignore=true
     */
    private Long lockedTime;
    /**
     * @Column
     */
    private Date testDate;
    /**
     * @ManyToMany fetch=eager
     * @JoinTable name=T_USER_ROLE joinColumn=USER_ID inverseJoinColumn=ROLE_ID
     */
    private List<Role> roles;

    @Column(nullable = false, unique = true)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Boolean getLocked() {
        return locked;
    }

    public void setLocked(Boolean locked) {
        this.locked = locked;
    }

    public Long getLockedTime() {
        return lockedTime;
    }

    public void setLockedTime(Long lockedTime) {
        this.lockedTime = lockedTime;
    }

    @ManyToMany(cascade = {CascadeType.REMOVE})
    @JoinTable(name = "T_USER_ROLE",
            joinColumns = {@JoinColumn(name = "USER_ID")},
            inverseJoinColumns = {@JoinColumn(name = "ROLE_ID")}
    )
    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }
}
